import request from '@/utils/request'

// ======================== RTU Modbus API ========================

// RTU - 测试连接
export function testRtuConnection(data) {
  return request({
    url: '/business/modbus/rtu/testConnection',
    method: 'post',
    data: data
  })
}

// RTU - 读取保持寄存器
export function readRtuHoldingRegisters(data) {
  return request({
    url: '/business/modbus/rtu/readHoldingRegisters',
    method: 'post',
    data: data
  })
}

// RTU - 读取输入寄存器
export function readRtuInputRegisters(data) {
  return request({
    url: '/business/modbus/rtu/readInputRegisters',
    method: 'post',
    data: data
  })
}

// RTU - 读取线圈
export function readRtuCoils(data) {
  return request({
    url: '/business/modbus/rtu/readCoils',
    method: 'post',
    data: data
  })
}

// RTU - 读取离散输入
export function readRtuDiscreteInputs(data) {
  return request({
    url: '/business/modbus/rtu/readDiscreteInputs',
    method: 'post',
    data: data
  })
}

// RTU - 写单个线圈
export function writeRtuSingleCoil(data) {
  return request({
    url: '/business/modbus/rtu/writeSingleCoil',
    method: 'post',
    data: data
  })
}

// RTU - 写单个寄存器
export function writeRtuSingleRegister(data) {
  return request({
    url: '/business/modbus/rtu/writeSingleRegister',
    method: 'post',
    data: data
  })
}

// (已移除) RTU - 批量读取

// RTU - 获取连接状态
export function getRtuConnectionStatus(data) {
  return request({
    url: '/business/modbus/rtu/connectionStatus',
    method: 'post',
    data: data
  })
}

// RTU - 获取设备统计信息
export function getRtuDeviceStatistics(data) {
  return request({
    url: '/business/modbus/rtu/deviceStatistics',
    method: 'post',
    data: data
  })
}

// RTU - 获取连接池统计信息
export function getRtuConnectionPoolStats() {
  return request({
    url: '/business/modbus/rtu/connectionPoolStats',
    method: 'get'
  })
}

// (已移除) RTU - 批量读取演示

// ======================== TCP Modbus API ========================

// TCP - 测试连接
export function testTcpConnection(data) {
  return request({
    url: '/business/modbus/tcp/testConnection',
    method: 'post',
    data: data
  })
}

// TCP - 读取保持寄存器
export function readTcpHoldingRegisters(data) {
  return request({
    url: '/business/modbus/tcp/readHoldingRegisters',
    method: 'post',
    data: data
  })
}

// TCP - 读取输入寄存器
export function readTcpInputRegisters(data) {
  return request({
    url: '/business/modbus/tcp/readInputRegisters',
    method: 'post',
    data: data
  })
}

// TCP - 读取线圈
export function readTcpCoils(data) {
  return request({
    url: '/business/modbus/tcp/readCoils',
    method: 'post',
    data: data
  })
}

// TCP - 读取离散输入
export function readTcpDiscreteInputs(data) {
  return request({
    url: '/business/modbus/tcp/readDiscreteInputs',
    method: 'post',
    data: data
  })
}

// TCP - 写单个线圈
export function writeTcpSingleCoil(data) {
  return request({
    url: '/business/modbus/tcp/writeSingleCoil',
    method: 'post',
    data: data
  })
}

// TCP - 写单个寄存器
export function writeTcpSingleRegister(data) {
  return request({
    url: '/business/modbus/tcp/writeSingleRegister',
    method: 'post',
    data: data
  })
}

// (已移除) TCP - 批量读取

// TCP - 获取连接状态
export function getTcpConnectionStatus(data) {
  return request({
    url: '/business/modbus/tcp/connectionStatus',
    method: 'post',
    data: data
  })
}

// TCP - 获取设备统计信息
export function getTcpDeviceStatistics(data) {
  return request({
    url: '/business/modbus/tcp/deviceStatistics',
    method: 'post',
    data: data
  })
}

// TCP - 获取连接池统计信息
export function getTcpConnectionPoolStats() {
  return request({
    url: '/business/modbus/tcp/connectionPoolStats',
    method: 'get'
  })
}

// (已移除) TCP - 批量读取演示

// ======================== 串口相关API ========================

// 测试串口连接
export function testSerialPort(data) {
  return request({
    url: '/business/modbus/serialPort/test',
    method: 'post',
    data: data
  })
}

// 获取可用串口列表
export function getAvailableSerialPorts() {
  return request({
    url: '/business/modbus/serialPort/available',
    method: 'get'
  })
}
